do a backtrace on babl_fatal()
authorØyvind Kolås <ok@src.gnome.org>
Sun, 28 Aug 2005 03:06:30 +0000 (03:06 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Sun, 28 Aug 2005 03:06:30 +0000 (03:06 +0000)
ChangeLog
babl/babl-component.c
babl/babl-conversion.c
babl/babl-fish.c
babl/babl-format.c
babl/babl-internal.c
babl/babl-internal.h
babl/babl-model.c
babl/babl-type.c

index 3f1e2a2721e57de4b6a16087cbdcd1d1ac957642..bfbd6f13d337ebaea6e2c54d6fd0f05e56e8f5ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-08-28  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-internal.[ch]: (babl_die): A function to call from
+       babl_fatal (...), invokes commands resulting in a backtrace, thus
+       giving context to where things broke.
+       * babl/babl-component.c: (babl_component_new):
+       * babl/babl-conversion.c: (babl_conversion_new):
+       * babl/babl-fish.c: (babl_conversion_find):
+       * babl/babl-format.c: (format_new), (babl_format_new):
+       * babl/babl-model.c: (babl_model_new):
+       * babl/babl-type.c: (babl_type_new): use babl_fatal() instead of
+       babl_log () on API mistakes.
+
 2005-08-28  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-pixel-format.c: removed
index 5a8e63cdf32e747813501825d22e3d824f02133c..e5f758b46bf87b988991d9fd5f8a25af3cf4a0db 100644 (file)
@@ -108,8 +108,7 @@ babl_component_new (const char *name,
       
       else
         {
-          babl_log ("unhandled argument '%s' for format '%s'", arg, name);
-          exit (-1);
+          babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
         }
     }
     
index a94da09781d07ee0ed9872552d22ec0606009e2d..76bc79cbc3fe41d81ad7fdab438949af24546bb6 100644 (file)
@@ -211,8 +211,7 @@ babl_conversion_new (Babl *source,
         }
       else
         {
-          babl_log ("unhandled argument '%s'", arg);
-          exit (-1);
+          babl_fatal ("unhandled argument '%s'", arg);
         }
 
       arg = va_arg (varg, char *);
index da7933e83786b8f99534710c033095ed34ae63e1..e33fd36ea05b4100eb00d8ed828091f54963000d 100644 (file)
@@ -108,10 +108,9 @@ BablConversion *babl_conversion_find (void *source,
 
   if (!data.result)
     {
-      babl_log ("args=('%s', '%s'): failed, aborting", 
-        data.source->instance.name, data.destination->instance.name);
-      exit (-1);
-      return NULL;
+      babl_fatal ("args=('%s', '%s'): failed, aborting", 
+          data.source->instance.name,
+          data.destination->instance.name);
     }
   return data.result;
 }
index 2a5319367fcc934d5345b3fb1b7f7b4fb8f5fd25..1607a8cce07eb44a7884d00695b2614c7dcefff1 100644 (file)
@@ -61,9 +61,8 @@ format_new (const char     *name,
             if (component[j] == model->component[i])
               goto component_found;
           }
-        babl_log ("matching source component for %s in model %s not found",
-           model->component[i]->instance.name, model->instance.name);
-        exit (-1);
+        babl_fatal ("matching source component for %s in model %s not found",
+                    model->component[i]->instance.name, model->instance.name);
         component_found:
         ;
       }
@@ -210,8 +209,7 @@ babl_format_new (const char *name,
       
       else
         {
-          babl_log ("unhandled argument '%s' for format '%s'", arg, name);
-          exit (-1);
+          babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
         }
     }
     
index 749d58f632bec4bce94e464c86d3eaa5c90a486a..8eba49141e776c816d3e38d33ba4ac2f8b857212 100644 (file)
@@ -54,6 +54,20 @@ babl_class_name (BablClassType klass)
  */
 int babl_hmpf_on_name_lookups = 0;
 
+#include <sys/types.h>
+#include <unistd.h>
+
+void
+babl_die (void)
+{
+  char buf[512];
+
+  sprintf (buf,"echo bt>/tmp/babl.gdb;"
+               "gdb -q --batch -x /tmp/babl.gdb --pid=%i 2>/dev/null", getpid());
+  system (buf);
+  exit (-1);
+}
+
 void
 babl_internal_init (void)
 {
index 81842f2ad1c39c98e0cc0c8474c6e6694bba7667..e8d31529344de21bdb5a83c9173bbdd795b7fb97 100644 (file)
@@ -39,6 +39,8 @@
 #include "babl-extension.h"
 /* */
 
+void babl_die (void);
+
 /**** LOGGER ****/
 #include <stdarg.h>
 
@@ -69,6 +71,13 @@ real_babl_log (const char *file,
 
 #define babl_log(args...)  real_babl_log(__FILE__, __LINE__, __FUNCTION__, args)
 
+#define babl_fatal(args...)  \
+  do{ \
+    real_babl_log(__FILE__, __LINE__, __FUNCTION__, args);\
+    babl_die();} \
+  while(0);
+
+
 /********************/
 
 #define BABL_CLASS_TYPE_IS_VALID(klass_type) \
@@ -107,24 +116,23 @@ type_name##_id (int id)                                       \
   return babl;                                                \
 }
 
-#define BABL_DEFINE_LOOKUP_BY_NAME(type_name)                 \
-Babl *                                                        \
-type_name (const char *name)                                  \
-{                                                             \
-  Babl *babl;                                                 \
-                                                              \
-  if (babl_hmpf_on_name_lookups)                              \
-    {                                                         \
-      babl_log ("%s(\"%s\"): hmpf!", __FUNCTION__, name);     \
-    }                                                         \
-  babl = db_exist (0, name);                                  \
-                                                              \
-  if (!babl)                                                  \
-    {                                                         \
-      babl_log ("%s(\"%s\"): not found", __FUNCTION__, name); \
-      exit (-1);                                              \
-    }                                                         \
-  return babl;                                                \
+#define BABL_DEFINE_LOOKUP_BY_NAME(type_name)                   \
+Babl *                                                          \
+type_name (const char *name)                                    \
+{                                                               \
+  Babl *babl;                                                   \
+                                                                \
+  if (babl_hmpf_on_name_lookups)                                \
+    {                                                           \
+      babl_log ("%s(\"%s\"): hmpf!", __FUNCTION__, name);       \
+    }                                                           \
+  babl = db_exist (0, name);                                    \
+                                                                \
+  if (!babl)                                                    \
+    {                                                           \
+      babl_fatal ("%s(\"%s\"): not found", __FUNCTION__, name); \
+    }                                                           \
+  return babl;                                                  \
 }
 
 #ifndef BABL_INIT_HOOK
index d3f12cfe3ba9f7fa81123e2b57dcfe5231f2328c..787f5b63cc21a84dde7ef959a28d33aa395995f8 100644 (file)
@@ -148,8 +148,7 @@ babl_model_new (void *first_argument,
       
       else
         {
-          babl_log ("unhandled argument '%s' for babl_model '%s'", arg, name);
-          exit (-1);
+          babl_fatal ("unhandled argument '%s' for babl_model '%s'", arg, name);
         }
 
       arg = va_arg (varg, char *);
index 7c8fc0c01482d49a6195dc5c8d69cf397216ca12..fbdb9c34ed751490ba11d49b1e4bdaf5f3cddce9 100644 (file)
@@ -125,8 +125,7 @@ babl_type_new (const char *name,
       
       else
         {
-          babl_log ("unhandled argument '%s' for format '%s'", arg, name);
-          exit (-1);
+          babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
         }
     }